;
(function() {
  'use strict';
  angular.module('controllers.accessSystem.accessResult', [])
    .controller('accessResultCtrl', accessResultCtrl);

  function accessResultCtrl($scope, accessResultService, $filter, CoreService, CoreLoading, COREDATA) {
    $scope.flag = {
      state: true,
      arrow: true,
      show: ''
    };
    var time = new Date();
    var year = time.getFullYear();
    var month = time.getMonth();
    var day = time.getDate();
    $scope.sendData = {
      timeTypeCode: '3',
      date: new Date(year, month - 1)
    };
    //监控统计方式
    $scope.$watch('sendData.timeTypeCode', function(newValue) {
      switch (newValue) {
        case '5':
          $scope.sendData.date = year - 1;
          break;
        case '3':
          $scope.sendData.date = new Date(year, month - 1);
          break;
        case '1':
          $scope.sendData.date = new Date(year, month, day - 1);
          break;
      }
    });
    //导出路径
    $scope.exportUrl = COREDATA.FORMPREFIX + 'accessSystem/export/result';
    $scope.initQuery = function() {
      accessResultService.queryTimeTypes(function(res) {
        if (res.state === '10000') {
          $scope.timeTypes = res.data;
        }
      });
    };
    $scope.search = function() {
      if (!$scope.flag.state) {
        $scope.flag.state = true;
        return;
      }
      CoreLoading.setState(true);
      $scope.title = accessResultService.sendTitle($scope.sendData);
      var send = accessResultService.sendData($scope.sendData);
      //导出参数
      $scope.exportParam = send;
      accessResultService.queryAccessResult(send, function(res) {
        if (res.state === '10000') {
          if (res.data.tqdata.length >= 1) {
            $scope.data = res.data;
            $scope.items = res.data.tqdata;
            $scope.flag.state = false;
            $scope.flag.arrow = false;
            $scope.flag.show = 'table';
          } else {
            CoreService.dialog('查询无数据');
            $scope.flag.state = true;
            $scope.flag.arrow = true;
            $scope.flag.show = '';
          }
        } else {
          CoreService.dialog('查询错误');
          $scope.flag.state = true;
          $scope.flag.arrow = true;
          $scope.flag.show = '';
        }
        CoreLoading.setState(false);
      });
    };
  }

  accessResultCtrl.$inject = ['$scope', 'accessResultService', '$filter', 'CoreService', 'CoreLoading', 'COREDATA'];
})();